{% extends 'base.html' %}
{% load crispy_forms_filters %}
{% load crispy_forms_tags %}

{% block title %}{{ title }} - 个人博客{% endblock %}

{% block content %}
<div class="container">
    <div class="row justify-content-center">
        <div class="col-lg-10">
            <div class="card shadow-sm">
                <div class="card-header bg-light">
                    <h2 class="mb-0">{{ title }}</h2>
                </div>
                <div class="card-body">
                    <form method="post" enctype="multipart/form-data">
                        {% csrf_token %}

                        <div class="row">
                            <div class="col-md-8">
                                {{ form.title|as_crispy_field }}
                            </div>
                            <div class="col-md-4">
                                {{ form.status|as_crispy_field }}
                            </div>
                        </div>

                        {{ form.content|as_crispy_field }}
                        {{ form.summary|as_crispy_field }}

                        <div class="row">
                            <div class="col-md-6">
                                {{ form.category|as_crispy_field }}
                            </div>
                            <div class="col-md-6">
                                {{ form.tags|as_crispy_field }}
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6">
                                {{ form.featured_image|as_crispy_field }}
                                {% if form.instance.featured_image %}
                                <div class="mb-3">
                                    <p>当前图片:</p>
                                    <img src="{{ form.instance.featured_image.url }}" alt="当前特色图片" class="img-fluid mb-2" style="max-height: 200px;">
                                </div>
                                {% endif %}
                            </div>
                            <div class="col-md-6">
                                {{ form.publish_date|as_crispy_field }}
                                <div class="form-text text-muted mb-3">
                                    如果选择"定时发布"，文章将在指定时间自动发布。
                                </div>
                            </div>
                        </div>

                        <div class="d-flex justify-content-between">
                            <a href="{% url 'home' %}" class="btn btn-secondary">取消</a>
                            <button type="submit" class="btn btn-primary">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

